document.addEventListener('DOMContentLoaded', function () {
    fetch('http://121.40.201.6/getEquipmentData.php')
        .then(response => response.json())
        .then(data => {
            const ctx = document.getElementById('productionChart').getContext('2d');
            const productionChart = new Chart(ctx, {
                type: 'bar',
                data: {
                    labels: data.map(item => item.name),
                    datasets: [{
                        label: '产量（万元）',
                        data: data.map(item => item.production),
                        backgroundColor: 'rgba(54, 162, 235, 0.6)',
                    }]
                },
                options: {
                    scales: {
                        y: {
                            beginAtZero: true
                        }
                    }
                }
            });

            const list = document.getElementById('equipmentList');
            data.forEach(item => {
                const li = document.createElement('li');
                li.textContent = `${item.name}: ¥${item.production}w - ${item.status}`;
                list.appendChild(li);
            });
        });
});

function exportChart() {
    const canvas = document.getElementById('productionChart');
    const url = canvas.toDataURL('image/png');
    const link = document.createElement('a');
    link.href = url;
    link.download = 'production_chart.png';
    link.click();
}
